Skip to content

scheduler: decouple the keyranges with different schedulers#9330

Merged
ti-chi-bot[bot] merged 19 commits intotikv:masterfrom
bufferflies:feature/decouple_keyrange
Jun 20, 2025
Merged

scheduler: decouple the keyranges with different schedulers#9330
ti-chi-bot[bot] merged 19 commits intotikv:masterfrom
bufferflies:feature/decouple_keyrange

Conversation

@bufferflies
Copy link
Contributor

@bufferflies bufferflies commented May 15, 2025

What problem does this PR solve?

Issue Number: Close #9302

What is changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test

Code changes

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

None.

Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
Signed-off-by: 童剑 <[email protected]>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels May 15, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented May 15, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added dco-signoff: yes Indicates the PR's author has signed the dco. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 15, 2025
@bufferflies bufferflies force-pushed the feature/decouple_keyrange branch 2 times, most recently from 7fa0925 to 808b7a1 Compare May 16, 2025 03:40
Signed-off-by: 童剑 <[email protected]>
@bufferflies bufferflies force-pushed the feature/decouple_keyrange branch from 808b7a1 to dbff105 Compare May 16, 2025 03:46
@codecov
Copy link

codecov bot commented May 16, 2025

Codecov Report

Attention: Patch coverage is 96.17834% with 6 lines in your changes missing coverage. Please review.

Project coverage is 76.18%. Comparing base (49c177a) to head (357c741).
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9330      +/-   ##
==========================================
- Coverage   76.18%   76.18%   -0.01%     
==========================================
  Files         478      479       +1     
  Lines       74794    74988     +194     
==========================================
+ Hits        56984    57129     +145     
- Misses      14282    14314      +32     
- Partials     3528     3545      +17     
Flag Coverage Δ
unittests 76.18% <96.17%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: 童剑 <[email protected]>
@bufferflies bufferflies force-pushed the feature/decouple_keyrange branch from 885ffe7 to 51f06d1 Compare May 22, 2025 12:24
@bufferflies bufferflies force-pushed the feature/decouple_keyrange branch from 51f06d1 to 01f2334 Compare May 27, 2025 07:48
@bufferflies bufferflies marked this pull request as ready for review May 27, 2025 07:48
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 27, 2025
Signed-off-by: 童剑 <[email protected]>
)

// KeyRangeManager is a manager for key ranges.
type KeyRangeManager struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems keyutil is a more proper package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to the new pkg pkg/schedule/rangelist

func (s *balanceLeaderScheduler) transferLeaderOut(solver *solver, collector *plan.Collector) *operator.Operator {
solver.Region = filter.SelectOneRegion(solver.RandLeaderRegions(solver.sourceStoreID(), s.conf.getRanges()),
rs := s.conf.getRanges()
if IsDefaultKeyRange(rs) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the hot region scheduler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hot region scheduler can schedule all the regions, not restricting this limit.

Signed-off-by: 童剑 <[email protected]>
@ti-chi-bot ti-chi-bot bot added the approved label Jun 9, 2025
@bufferflies
Copy link
Contributor Author

ping @rleungx again

for _, r := range rs {
s.sortedKeyRanges.Append(r.StartKey, r.EndKey)
}
s.sortedKeyRanges.SortAndDeduce()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For every time we append, we need to sort?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

@bufferflies bufferflies Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, using adjust function to check the two regions

Signed-off-by: 童剑 <[email protected]>
@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 10, 2025

// MaxKeyWithBoundary returns the bigger key for the given keys.
// it is different from MaxKey, if the key is empty and the boundary is right, the empty key is biggest,
func MaxKeyWithBoundary(a, b []byte, opt boundary) []byte {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about changing to MaxStartKey/MinEndKey? The boundary is useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

for i := 1; i < len(rs.krs); i++ {
last := res[len(res)-1]
if last.IsAdjacent(rs.krs[i]) {
last.StartKey = MinKeyWithBoundary(last.StartKey, rs.krs[i].StartKey, left)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has already been sorted, no need to compare?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, done

rs := s.conf.getRanges()
if IsDefaultKeyRange(rs) {
km := solver.GetKeyRangeManager()
rs = km.GetNonOverlappingKeyRanges(&rs[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it slow down the balance leader's speed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If one balance-keyrange job is running, the pick ranges of the scheduling regions become small. Otherwise, the rs is the same with the master; this function does not influence the select the source region.

solver.Step++
var sourceIndex int

rs := s.conf.Ranges
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we change the range manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config can only be changed by the scatter range scheduler. This scatter scheduler only picks the given key-range regions, there is no any conflict

Copy link
Member

@rleungx rleungx Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this config is exposed. We can set them through pd-ctl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I used the scheduler name to distinguish the scheduler from the scatter-scheduler

Signed-off-by: 童剑 <[email protected]>
@bufferflies bufferflies force-pushed the feature/decouple_keyrange branch from 6e774db to 9db3d05 Compare June 18, 2025 11:15
@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 18, 2025
@bufferflies bufferflies force-pushed the feature/decouple_keyrange branch from e93b5b6 to 255029d Compare June 19, 2025 07:04
rs := s.conf.getRanges()
if s.GetName() == types.BalanceLeaderScheduler.String() {
km := solver.GetKeyRangeManager()
rs = km.GetNonOverlappingKeyRanges(&rs[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about skipping it if there is no job?

Copy link
Member

@rleungx rleungx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest LGTM

@ti-chi-bot ti-chi-bot bot added the lgtm label Jun 19, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jun 19, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lhy1024, rleungx

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 19, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jun 19, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-06-09 03:02:19.409732585 +0000 UTC m=+237717.638047833: ☑️ agreed by lhy1024.
  • 2025-06-19 10:36:22.91088544 +0000 UTC m=+354435.634064424: ☑️ agreed by rleungx.

@bufferflies bufferflies force-pushed the feature/decouple_keyrange branch from 3a92d59 to 3706344 Compare June 19, 2025 11:13
@bufferflies bufferflies force-pushed the feature/decouple_keyrange branch from 7bda573 to 394843c Compare June 20, 2025 01:08
@bufferflies bufferflies force-pushed the feature/decouple_keyrange branch from 854a502 to 357c741 Compare June 20, 2025 02:41
@ti-chi-bot ti-chi-bot bot merged commit 206b56e into tikv:master Jun 20, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scheduler: decouple the keyranges with different schedulers

3 participants